
<script type="text/javascript">

</script>
<style media="screen">
  .cust{
    width: 40% !important;
    float: left!important;
  }
</style>

<br>
<div class="ui  container">
  <div class="ui segment">
    <div class="ui huge header">
      <%= @manage_title %>
    </div>
    <form class="" action="/webadmin/bill/deletebillss" method="post">
      <div class="ui buttons">
        <!-- <a href="/system/bills/new" class="ui green basic button">增加</a> -->
        <button type="submit" class="ui basic red button">批量删除</button>
        <input type="hidden" name="ids" value="" id="bills_delete">
      </div>
    </form>
  </div>
  <div class="ui load segment">
    <div class="ui dimmer">
    <div class="content">
      <div class="center">
        <h2 class="ui inverted icon header">
          <i class="progress icon"></i>
          <span id="loadMessage">正在保存更改......<span>
        </h2>
      </div>
    </div>
  </div>
  <div class="ui container">


    <table class="ui twelve column celled table">
      <thead>
        <tr>
        <th>
          全选／反选 <br>
          <div class="ui master checkbox">
            <input type="checkbox">
            <label for=""></label>
          </div>
        </th>
        <th>编号</th>
        <th>总金额</th>
        <th>详细详细</th>
        <th>汇款银行</th>
        <th>状态</th>
        <th>发起时间</th>
        <th>发起用户</th>
        <th>状态更新时间</th>
      </tr></thead>
      <tbody>
        <% if @bills.length > 0 and @bills %>
        <% @bills.each do |bill| %>
        <tr>
          <td style="word-break:break-all;">
            <div class="ui child checkbox" billid="<%= bill.id %>">
              <input type="checkbox" tabindex="0">
              <label for=""></label>
            </div>
          </td>
          <td style="word-break:break-all;"><%= bill.id %></td>

          <td style="word-break:break-all;"><%= bill.amount %></td>
          <td style="word-break:break-all;"><%= bill.info %></td>
          <% @bill_bank = bill.bank_card %>
          <td>
            <ul>
              <li><%= @bill_bank ? @bill_bank.card_number : "" %></li>
              <li><%= @bill_bank ? @bill_bank.bank_address : "" %></li>
              <li><%= @bill_bank ? @bill_bank.bank_real_name : "" %></li>
            </ul>
          </td>


          <td style="width:200px;">
            <select  id="status<%=bill.id.to_s %>" name="skills" class="ui fluid dropdown">
              <option <%=bill.status==0 ? 'selected="selected"' : "" %>  value="0" >正在处理</option>
              <option <%=bill.status==1 ? 'selected="selected"' : "" %>  value="1">已到账</option>
              <option <%=bill.status==2 ? 'selected="selected"' : "" %>  value="2">已请求</option>
            </select>

              <script type="text/javascript">
        			$("#status<%=bill.id.to_s %>").dropdown({
                  onChange: function(value, text, $selectedItem) {
                    $('.ui.load.segment').dimmer('show');
                    $.get('/system/withdraws/change_status/'+'<%=bill.id.to_s %>', {state: value}, function(result){
                      $selectedItem.val(result);
                      $('.ui.load.segment').dimmer('hide');
                    });
                  }
        				});
        			</script>
          </td>
          <td style="word-break:break-all;"><%= bill.created_at.strftime("%Y-%m-%d %H:%M:%S") %></td>
          <td style="word-break:break-all;">
            <%= bill.updated_at.strftime("%Y-%m-%d %H:%M:%S") %>
          </td>


        </tr>
        <% end %>
        <% else %>
          <p>暂时没有数据</p>
        <% end %>
      </tbody>
      <tfoot>
        <tr><th colspan="4">
          <?php echo $pagination; ?>
        </th>
      </tr></tfoot>
    </table>
    </div>
  </div>
</div>
<script type="text/javascript">
$('.master.checkbox')
.checkbox({
  // check all children
  onChecked: function() {
    var
      $childCheckbox  = $('.child.checkbox');
    ;
    $childCheckbox.checkbox('check');
  },
  // uncheck all children
  onUnchecked: function() {
    var
      $childCheckbox  = $('.child.checkbox');
    ;
    $childCheckbox.checkbox('uncheck');
  }
})
;
var ids = '';
$('.child.checkbox').each(function(){
    var id = $(this).attr('billid');
    $(this).checkbox({
      'onChecked': function(){
        ids = ids+ id+ "|";
        $("#bills_delete").val(ids);

      },
      'onUnchecked': function(){
        var regx = new RegExp(id+'\\|');
        ids = ids.replace(regx, '');

        $("#bills_delete").val(ids);
        if (ids=='') {
          $('.master.checkbox').checkbox('uncheck');
        }
      }
    });
});

$("#checkSeller").checkbox({
  onChecked: function() {
    console.log('checked');
    $('.ui.load.segment').dimmer('show');
    $('#loadMessage').html("正在保存更改......");
    var bill_id = $("#checkSeller").attr("data-id");
    $.get('/system/bills/enable_seller/'+bill_id, function(result){
      if (result == '1') {
        $('#loadMessage').html("更改成功！");
        $('.ui.load.segment').dimmer('hide');
      }
      if (result == '0') {
        $('#loadMessage').html("更改失败，请检查网络");
        $('.ui.load.segment').dimmer('hide');
      }
    });
  },
  onUnchecked: function() {
    console.log('unchecked');
  $('.ui.load.segment').dimmer('show');
  $('#loadMessage').html("正在保存更改......");
  var bill_id = $("#checkSeller").attr("data-id");
  $.get('/system/bills/disable_seller/'+bill_id, function(result){
    if (result == '1') {
      $('#loadMessage').html("更改成功！");
      $('.ui.load.segment').dimmer('hide');
    }
    if (result == '0') {
      $('#loadMessage').html("更改失败，请检查网络");
      $('.ui.load.segment').dimmer('hide');
    }
  });
  }
});
</script>
<div class="ui modal" id="changeAmountModal">
  <i class="close icon"></i>
<div class="header">
    输入交易额
</div>

<div class="actions">
  <div class="two fluid ui  buttons">
    <div class="ui cancel red basic  button">
      <i class="remove icon"></i>
      取消
    </div>
    <div class="ui ok green basic  button">
      <i class="checkmark icon"></i>
      保存
    </div>
  </div>
</div>
<div class="ui dimmer">
  <div class="content">
    <div class="center">
      <h2 class="ui inverted icon header">
        <i class="progress icon"></i>
        <span id="loadMessage">正在保存更改......<span>
      </h2>
    </div>
  </div>
</div>
</div>
